package wrongWordsHandling;

import java.util.ArrayList;
import java.util.List;

import Data.DictionaryData;
import Data.SuggestedWord;

public class Suggestion {
	List<String> SuggestedList = new ArrayList<String>();


	public List<String> suggestion(String wrongWord)
	{
		wrongWord=wrongWord.toUpperCase();

		filterWordList(wrongWord);
		SuggestedWord.editWordList(SuggestedList);// enter
		return SuggestedList;
	}
	private void filterWordList(String wrongWord) {
		int length=wrongWord.length();
		DictionaryData dictionary_data = new DictionaryData();
		for (String input: dictionary_data.getWordList()){
			if(input.length() == length){
				int notMatchNum=0;
				for (int i=0 ; i< length; i++){
					if(input.charAt(i) != wrongWord.charAt(i)){
						notMatchNum++;
						if(notMatchNum>1){
							break;
						}
					}
					if (i==length-1){
						addSuggestion(input.toLowerCase());
					}
				}
			}
		}
	}

	private void addSuggestion(String suggestedWord) {
		SuggestedList.add(suggestedWord);
	}
}
